﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Ribbon;

namespace DentistApplication
{
    /// <summary>
    /// Interaction logic for RibbonWindow1.xaml
    /// </summary>
    public partial class NewServicesWindow : RibbonWindow
    {
        public List<Service> ServiceList = new List<Service>(); //w tej liscie tak? yeap a recognition? Tu nie ma recognition , tu tylko notujemy co robilismy z pacjentem. ok.. to recognition bedzie tu:
        List<string> teeth = new List<string>();
        List<int> serviceTypesIDs = new List<int>();
        public NewServicesWindow(Patient p, List<string> teeth)
        {
            InitializeComponent();
            la_chosenPatient.Content += p.firstname + " " + p.lastname;
            ListV_services.ItemsSource = DatabaseHandler.getAllServiceTypes();
            //comboBDentist.ItemsSource = DatabaseHandler.getDentists();
            serviceTypesIDs = DatabaseHandler.getAllServiceTypesIDs();
            this.teeth = teeth;
            listB_teeth.ItemsSource = this.teeth;

            for (int i = 11; i < 19; i++)
            {
                comboBox1.Items.Add(i.ToString());
            }
            for (int i = 21; i < 29; i++)
            {
                comboBox1.Items.Add(i.ToString());
            }
            for (int i = 31; i < 39; i++)
            {
                comboBox1.Items.Add(i.ToString());
            }
            for (int i = 41; i < 49; i++)
            {
                comboBox1.Items.Add(i.ToString());
            }
            btnAdd.Visibility = Visibility.Hidden;
        }

        
        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
      
        private void button1_Click_2(object sender, RoutedEventArgs e)
        {            
            //DatabaseHandler.addVisitToDatabase(this.currentVisit);
            //Service ToAddService = new Service
            //{
            //    id_type = ListV_services.SelectedIndex + 1,
            //    tooth = this.tooth
            //};
            //ServiceList.Add(ToAddService);
            foreach (string s in this.teeth)
            {
                addToothToList(Convert.ToInt32(s));
            }
            this.Close();

        }

        private void addToothToList(int toothToAdd)
        {
            Service Serv = new Service
            {
                id_type = this.serviceTypesIDs.ElementAt(ListV_services.SelectedIndex)   ,
                tooth = toothToAdd,
                notes = tbNotes.Text
            };
            ServiceList.Add(Serv);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            ListV_services.ItemsSource = DatabaseHandler.getGroupServiceTypes(button4.Content.ToString());
            serviceTypesIDs = DatabaseHandler.getGroupServiceTypesIDs(button4.Content.ToString());
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            ListV_services.ItemsSource = DatabaseHandler.getGroupServiceTypes(button2.Content.ToString());
            serviceTypesIDs = DatabaseHandler.getGroupServiceTypesIDs(button2.Content.ToString());
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            ListV_services.ItemsSource = DatabaseHandler.getGroupServiceTypes(button3.Content.ToString());
            serviceTypesIDs = DatabaseHandler.getGroupServiceTypesIDs(button3.Content.ToString());
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            ListV_services.ItemsSource = DatabaseHandler.getGroupServiceTypes(button5.Content.ToString());
            serviceTypesIDs = DatabaseHandler.getGroupServiceTypesIDs(button5.Content.ToString());
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            ListV_services.ItemsSource = DatabaseHandler.getGroupServiceTypes(button6.Content.ToString());
            serviceTypesIDs = DatabaseHandler.getGroupServiceTypesIDs(button6.Content.ToString());
        }

        private void button7_Click(object sender, RoutedEventArgs e)
        {
            ListV_services.ItemsSource = DatabaseHandler.getGroupServiceTypes(button7.Content.ToString());
            serviceTypesIDs = DatabaseHandler.getGroupServiceTypesIDs(button7.Content.ToString());
        }

        private void button9_Click(object sender, RoutedEventArgs e)
        {
            
            try
            {
                string b = listB_teeth.SelectedValue.ToString();
                this.teeth.Remove(b);
                listB_teeth.ItemsSource = this.teeth;
                listB_teeth.Items.Refresh();
            }
            catch
            {

            }

        }

        private void button8_Click(object sender, RoutedEventArgs e)
        {

            
            string b = ""; 
            try
            {
                b = comboBox1.SelectedValue.ToString();
                var help = this.teeth.Single(s => s == b);
            }
            catch
            {
                if (b != "")
                {
                this.teeth.Add(b);
                listB_teeth.ItemsSource = this.teeth;
                listB_teeth.Items.Refresh();
                }
            }
        }

        private void ListV_services_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListV_services.SelectedIndex == -1)
            {
                btnAdd.Visibility = Visibility.Hidden;
                dgServices.ItemsSource = ServiceList;
            }
            else
            {
                btnAdd.Visibility = Visibility.Visible;
            }
        }

    }
}
